package cn.south.campus.common.model.bo;


import cn.south.campus.common.model.enums.CommonEnums;
import cn.south.campus.common.model.enums.ResponseCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2022/5/7 15:28
 */
public class Result<R> {
    private boolean success = true;
    private String code;
    private String tips;
    private R data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }

    public R getData() {
        return data;
    }

    public void setData(R data) {
        this.data = data;
    }

    public Result(boolean success, String code, String tips) {
        this.success = success;
        this.code = code;
        this.tips = tips;
    }

    public Result(String code, String desc, String tips) {
        this.code = code;
        this.tips = tips;
    }

    public Result(boolean success, String code, String tips, R data) {
        this.success = success;
        this.code = code;
        this.data = data;
        this.tips = tips;
    }

    public Result() {
    }

    public static Result<Void> success() {
        return new Result<>(true, CommonEnums.SUCCESS.getCode(), CommonEnums.SUCCESS.getTips());
    }

    public static <R> Result<R> success(R data) {
        return new Result<>(true, CommonEnums.SUCCESS.getCode(), CommonEnums.SUCCESS.getTips(), data);
    }

    public static Result<Void> error() {
        return new Result<>(false, CommonEnums.SYSTEM_ERROR.getCode(), CommonEnums.SYSTEM_ERROR.getTips());
    }

    public static Result<Void> error(ResponseCode enums) {
        return new Result<>(false, enums.getCode(), enums.getTips());
    }

    public static Result<Void> error(String code, String tips) {
        return new Result<>(false, code, tips);
    }
}
